Skip to content

Conversation

@nyurik
Copy link
Member

@nyurik nyurik commented Oct 20, 2025

tests became a bit hard to manage, so moving them into separate files. The integration tests were easy to move into tests/ dir, but the unit tests should be in a separate file because we don't want to grow public API surface

tests became a bit hard to manage, so moving them into separate files. The integration tests were easy to move into tests/ dir, but the unit tests should be in a separate file because we don't want to grow public API surface
@nyurik nyurik requested review from Copilot and tegimeki October 20, 2025 18:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reorganizes the test suite by moving integration tests from the main library module to separate test files. Unit tests that exercise private parser functions are moved to a new src/parser_tests.rs module file, while integration tests that use the public API are relocated to tests/parsing.rs. This refactoring improves code maintainability without expanding the public API surface.

Key changes:

  • Created tests/parsing.rs for integration tests using public API
  • Created src/parser_tests.rs for unit tests of internal parser functions
  • Made several parser functions pub(crate) to enable internal testing
  • Made ValDescription struct fields public to support integration test assertions

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/parsing.rs New integration test file containing tests that use the public Dbc API
src/parser_tests.rs New unit test module containing parser function tests
src/lib.rs Removed test module, added parser_tests module import, made ValDescription fields public
src/parser.rs Removed inline test module, changed several parser functions from private to pub(crate) visibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +209 to +210
let message_id = MessageId::Extended(2 ^ 29);
assert_eq!(message_id.raw(), 2 ^ 29 | 1 << 31);
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XOR operator ^ is being used where bitwise OR | is likely intended. 2 ^ 29 evaluates to 31, not a 29-bit shifted value. This should be 2 | (1 << 29) or 2 + (1 << 29) if setting bit 29.

Suggested change
let message_id = MessageId::Extended(2 ^ 29);
assert_eq!(message_id.raw(), 2 ^ 29 | 1 << 31);
let message_id = MessageId::Extended(2 | 1 << 29);
assert_eq!(message_id.raw(), (2 | 1 << 29) | 1 << 31);

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a valid critique. There isn't a valid reason to xor 2 and 29.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should just hardcode some value (in a separate PR) using hex notation?

@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nyurik nyurik requested a review from amaraxmonika October 21, 2025 21:20
#[test]
fn signal_comment_test() {
let def = r#"
CM_ SG_ 193 KLU_R_X "This is a signal comment test";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we think about using an indo macro here to clean up formatting? https://docs.rs/indoc/latest/indoc/#using-indoc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny - I was actually thinking initially of using it myself - it is great for multiline strings. That said, in this case I think it would be less than ideal because indoc introduces some string handling magic like removing prefix spaces on each line - nothing too big, but that makes the test string content less certain - which is not that great for a test case. In my examples, I only remove initial spaces of the first line, and the rest is exactly as written.

@nyurik nyurik merged commit 0c82e6a into oxibus:main Oct 22, 2025
8 checks passed
@nyurik nyurik deleted the test-split branch October 22, 2025 16:24
@nyurik nyurik mentioned this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants